let name = "alen"

function chi() {
    name = "alice"; // 引用外部的全局变量，将外部name这个全局变量的值修改了
}

chi();
console.log(name)

//
var n = "alex";

// 内置函数，定时触发任务
setTimeout(function () {
    console.log("一号工具人:" + n) // 一号工具人是不安全的，因为他是外部全局变量
}, 5000);

//
var n = "nexora"
console.log("二号工具人:" + n)

function fn() {
    let love = "haha";
}

// console.log(love)

(function () {
    var name = "alex";
    setTimeout(function () {
        console.log("工具人:" + name);
    }, 5000);
})();

let encrypt_tool = (function () {
    let log_msg = 'start to encrypt ...\n'
    // encrypt func
    let encrypt = function (data) {  // datasource
        console.log(log_msg);  //  print log info
        // return after encrypt
        return atob(data); // make a Base64 code string to decode original start binary code
    }
    // decode
    let decrypt = function (en_data) {
        let log_msg_2 = 'start to decrypt ...\n'
        console.log(log_msg_2);   // print log info
        // return after decode message
        return btoa(en_data);
    }
    // outside will use it function. you should return one, and encrypt func
    return {"encrypt": encrypt, "decrypt": decrypt}
})();


// encrypt_tool = {'encrypt': encrypt, 'decrypt': decrypt};
en_data = encrypt_tool.encrypt("i love you")
console.log(en_data);
console.log(encrypt_tool.decrypt(en_data));

